using System;
using Microsoft.Xna.Framework;

namespace Imagination.Physics
{
    /// <summary>
    /// InertiaCalculator contains math functions for calculating the 
    /// moment of inertia for different shapes.
    /// </summary>
	public static class InertiaCalculator
	{
		public static Matrix CalcRectangularPrism(float mass,
			float length, float width, float height)
		{
			float Ixx = mass/12.0f * ((width * width) +	(height * height));
			float Iyy = mass/12.0f * ((length * length) + (width * width));
			float Izz = mass/12.0f * ((length * length) + (height * height));
				
			Matrix inertia = new Matrix();
			inertia.M11 = Ixx;
			inertia.M22 = Iyy;
			inertia.M33 = Izz;
			inertia.M44 = 1;
			return inertia;
		}
		
		public static Matrix CalcSphere(float mass, float radius)
		{
			float Iall = 0.4f * mass * radius * radius;
            Matrix inertia = new Matrix();
			inertia.M11 = inertia.M22 = inertia.M33 = Iall;
			inertia.M44 = 1;
			return inertia;
		}
	}
}
